from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QMessageBox
from edb.login import Ui_Dialog

class LOGIN(QDialog):
    def __init__(self, signal, parent=None):
        super().__init__(parent)
        # signal emit bool value
        self.signal = signal
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.login.clicked.connect(self.login_in)
        self.ui.close.clicked.connect(self.close)
        # 无边框
        self._set_none_broder()

    def login_in(self):
        if self.ui.account.text() == 'admin':
            if self.ui.psw.text() == 'admin':
                self.signal.emit(True)
                self.hide()
                return
        QMessageBox.information(self, "登录提示", "登录失败，检查账号密码是否输入正确！")

    def _set_none_broder(self):
        # 无边框
        self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
        # 添加阴影
        self.setAttribute(Qt.WA_TranslucentBackground)
        # effect = QGraphicsDropShadowEffect(self)
        # effect.setBlurRadius(12)
        # effect.setOffset(0, 0)
        # effect.setColor(Qt.gray)
        # self.setGraphicsEffect(effect)

    def closeEvent(self, a0) -> None:
        reply = QMessageBox.question(self, '登陆中', '是否退出', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.signal.emit(False)
            a0.accept()
        else:
            a0.ignore()